package com.allwees.bs.c.module.order.chain.create.handler;

import com.allwees.bs.c.module.order.chain.create.request.OrderCreateRequest;
import com.allwees.bs.c.module.order.service.IOrderService;
import com.allwees.bs.core.model.payment.enums.EPaymentType;
import com.allwees.core.common.context.AbstractHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderSavedHandler  extends AbstractHandler<OrderCreateRequest> {

    @Autowired
    private IOrderService orderService;

    @Override
    public OrderCreateRequest handler(OrderCreateRequest request) {
        if(request.isCheckOrder()){
            return request;
        }
        if (request.isAmtPayedOfCoupon()) {
            orderService.payOrder(request.getUuid(), "", EPaymentType.COUPON);
        }
        return doNext(request);
    }
}
